<template>
    <div>
        <my-search></my-search>
        <swiper indicator-dots=true>
            <swiper-item :key='index' v-for="(item,index) in swiperData">
                <image :src='item.image_src' class="slide-image"></image>
            </swiper-item>
        </swiper>
        <div class="menu">
            <div :key='index' v-for='(item, index) in menuData' class="menu-item">
                <image :src='item.image_src'></image>
            </div>
        </div>
        <div class="floor" :key='index' v-for='(item,index) in floorData1'>
            <div class="floor_title">
                <img :src='item.floor_title.image_src'>
            </div>
            <div class="floor_content">
                <div class="left">
                    <img :src='item.leftImagePath'>
                </div>
                <div class="right">
                    <img :key="i" v-for="(img,i) in item.product_list" :src="img.image_src">
                </div>
            </div>
        </div>
        <div @click="toTop" class="top" v-show="flag">
            ︿
            <p>顶部</p>
        </div>
    </div>
</template>

<script>
import request from "../../utils/request.js"
import mysearch from "../../components/mysearch.vue"
export default {
    data() {
        return {
            swiperData:[],
            menuData:[],
            floorData:[],
            flag:false
        }
    },
    components: {
        'my-search':mysearch
    },
    computed: {
        floorData1 () {
            return this.floorData.map(item=> { 
                item.leftImagePath = item.product_list[0].image_src
                item.product_list = item.product_list.filter((item,index)=>{
                    // 去掉第一张
                    return index > 0
                })
                return item;
            })
        }
    },
    methods: {
        toTop() {
            wx.pageScrollTo({
                scrollTop:0
            })
        },
        async initData() {
            let swiperRes = await request('home/swiperdata')
            this.swiperData = swiperRes.data.message
            let menuRes = await request('home/catitems')
            this.menuData = menuRes.data.message
            let floorRes = await request('home/floordata')
            this.floorData = floorRes.data.message
        }
    },
    created() {
        // mpvue.request({
        //     url:'https://www.ehomespace.com/api/public/v1/home/swiperdata',
        //     method:"get",
        //     success: (res)=> {
        //         this.swiperData=res.data.message
        //     }
        // }),
        // request('home/swiperdata') 
        //     .then(res=> {
        //         this.swiperData = res.data.message
        //     })
        // mpvue.request({
        //     url:'https://www.ehomespace.com/api/public/v1/home/catitems',
        //     method:"get",
        //     success: (res)=> {
        //         this.menuData = res.data.message
        //     }
        // })
        // request('home/catitems') 
        //     .then(res=> {
        //         this.menuData = res.data.message
        //     })

            this.initData()
    },
     onPullDownRefresh () {
        // 下拉刷新时触发，从新获取页面相关后台数据
        this.initData()
    },
    onPageScroll(param) {
        this.flag = param.scrollTop > 50
    }
}
</script>

<style scoped lang="scss">
    @import 'main.scss';
    
</style>
